package cn.iocoder.yudao.module.crm.dal.mysql.robotcluetransrule;

import java.time.LocalDateTime;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.crm.dal.dataobject.robotCluetransrule.RobotClueTransRuleDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.crm.controller.admin.robotcluetransrule.vo.*;
import org.apache.ibatis.annotations.Select;

/**
 * 转化规则 Mapper
 *
 * @author 数创万维
 */
@Mapper
public interface RobotClueTransRuleMapper extends BaseMapperX<RobotClueTransRuleDO> {

    default PageResult<RobotClueTransRuleDO> selectPage(RobotClueTransRulePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RobotClueTransRuleDO>()
                .eqIfPresent(RobotClueTransRuleDO::getTaskId, reqVO.getTaskId())
                .eqIfPresent(RobotClueTransRuleDO::getStatus, reqVO.getStatus())
//                .eqIfPresent(RobotClueTransRuleDO::getMinInterval, reqVO.getMinInterval())
                .eqIfPresent(RobotClueTransRuleDO::getTransPos, reqVO.getTransPos())
                .eqIfPresent(RobotClueTransRuleDO::getModuleId, reqVO.getModuleId())
                .betweenIfPresent(RobotClueTransRuleDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(RobotClueTransRuleDO::getId));
    }

    default List<RobotClueTransRuleDO> getExecutableList(LocalDateTime nextTime) {
        return selectList(new LambdaQueryWrapperX<RobotClueTransRuleDO>().eq(RobotClueTransRuleDO::getStatus, 1).le(RobotClueTransRuleDO::getNextQueryTime, nextTime));
    }

}